<!DOCTYPE html>
<html>
<head>

<script src="../Jquery/Jquery-3.3.1.js" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap.css">

<meta charset="UTF-8">
<title>宿管注册页</title>
</head>
<body>
	<div style="text-align: center;" class="container" id="content">
		<h2>注册新宿管员</h2>
		<div class="col-md-4">
			<!--  -->
			<form id="role_form" class="bs-example bs-example-form col-md-5" role="form" style="margin: 20px 0 10px 0;">
				<!--  -->
				<br>
				<!--  -->
				<input type="text" name="hpname" placeholder="请输入用户名" class="form-control" maxlength="10" id="houseparent_name">
				<!--  -->
				<br>
				<!--  -->
				<input type="text" name="idCard" placeholder="请输入身份证号" class="form-control" maxlength="18" id="houseparent_id_card">
				<!--  -->
				<br>
				<!--  -->
				<input type="text" name="phone" placeholder="请输入电话" class="form-control" maxlength="25" id="houseparent_phone">
				<!--  -->
				<br>
				<!--  -->
				<input type="password" name="password" placeholder="请输入密码" class="form-control" maxlength="16"
					id="houseparent_pwd00">
				<!--  -->
				<br>
				<!--  -->
				<input type="password" name="password00" placeholder="请再次确认密码" class="form-control" maxlength="16"
					id="houseparent_pwd11">
				<!--  -->
				<br>
				<!--  -->
				<div class="form-group" style="text-align: center">
					<!--  -->
					<input type="button" value="注册" id="sub_reg" class="btn btn-default">
					<!--  -->
					<button class="btn btn-default" type="reset">重置</button>
				</div>
				<!--  -->
			</form>
		</div>
		<!--  -->
		<br>

		<div class="panel-footer">
			<a href="Login.html">返回登录页</a>
		</div>

	</div>
</body>

<script type="text/javascript">
	$('#sub_reg')
			.click(
					function() {
						var url = "/dormitory/HouseParents/registration";
						var data = $("#role_form").serialize();

						var hpName = $('#houseparent_name').val();
						var hpIdCard = $('#houseparent_id_card').val();
						var hpPhone = $('#houseparent_phone').val();
						var pwd0 = $('#houseparent_pwd00').val();
						var pwd1 = $('#houseparent_pwd11').val();

						/*禁空*/
						if (hpName == null || hpName == '' || hpIdCard == null || hpIdCard == '' || hpPhone == null
								|| hpPhone == '' || pwd0 == null || pwd0 == '' || pwd1 == null || pwd1 == '') {
							alert("未填完")
							return;
						}

						/**/
						if (hpName.length < 3) {
							alert("用户名不得少于3位");
							return;
						}

						/*身份证号正则表达式,18位*/
						var expression = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
						var exp = new RegExp(expression);
						if (exp.test(hpIdCard) == false) {
							alert('身份证号码无效')
							return;
						}

						/* 至少9位的数字: ^\d{9,}$ */
						var expression01 = /^\d{9,}$/;
						var exp01 = new RegExp(expression01);
						if (exp01.test(hpPhone) == false) {
							alert('手机号码格式有误')
							return;
						}

						/**/
						if (pwd0.length < 3) {
							alert("密码不得少于3位");
							return;
						}

						/**/
						if (pwd0 !== pwd1) {
							alert("两次输入的密码不一致")
							return;
						}

						$.ajax({
							"url" : url,
							"data" : data,
							"type" : "POST",
							"dataType" : "json",
							"success" : function(json) {
								if (json.state == 200) {
									alert("注册成功");
									location.href = "Login.html";
								} else {
									alert(json.message);
								}
							}
						});
					});
</script>

</html>